//
//  IsSafeData.m
//  General tools
//
//  Created by Flyer on 2016/8/9.
//  Copyright © 2016年 Flyer. All rights reserved.
//

#import "IsSafeData.h"

@implementation IsSafeData

+ (BOOL)IsStringSate:(NSString *)string{
    if (string == nil || string == NULL || [string isKindOfClass:[NSNull class]] || [[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {
        return NO;
    }
    return YES;
}

+ (BOOL)IsArraySafe:(NSArray*)array
{
    if (array==nil || [array isEqual:[NSNull null]] || ![array isKindOfClass:[NSArray class]] || array.count<1) {
        return NO;
    }
    return YES;
}
+ (BOOL)IsDictionarySafe:(NSDictionary*)dictionary
{
    if (dictionary==nil || [dictionary isEqual:[NSNull null]] || ![dictionary isKindOfClass:[NSDictionary class]] || dictionary.count<1) {
        return NO;
    }
    return YES;
}

// 是否文本内容为空
+ (BOOL)IsTextFieldEmpty:(NSString*)content
{
    BOOL bRight = YES;
    
    if (content) {
        content = [content stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        if (content.length > 1) {
            bRight = NO;
        }
    }
    return bRight;
}

// NSMutableArray 添加 object时保证不出错
+ (BOOL)arraySafeAddObject:(NSMutableArray*)array Object:(id)object
{
    if (array == nil) {
        NSLog(@"%s array is nil", __func__);
        return FALSE;
    }else if (object == nil) {
        NSLog(@"%s object is nil", __func__);
        return FALSE;
    }
    [array addObject:object];
    return TRUE;
}

+ (NSObject*)arraySafeGetObject:(NSArray*)array index:(NSUInteger)uiIndex
{
    if (array && ![array isEqual:[NSNull null]] && array.count>uiIndex) {
        return [array objectAtIndex:uiIndex];
    }
    return nil;
}

@end
